class Admin::StoreController < Admin::BaseController
  
  active_scaffold :store do |config|
      config.label = "快印店"
      config.columns = [:merchant, :name, :address, :area, :email, :province, :city, :map, :phone, :mobile_phone, :work_time, :disabled, :passed, :certified, :description, :props]
      config.columns << :upload_logo
      config.columns << :upload_store_image
      config.columns << :upload_license
      
      config.create.multipart  = true
      config.create.link.inline = false
      config.create.columns = [:merchant, :name, :address, :area, :email, :province, :city, :map, :phone, :mobile_phone, :work_time, :passed, :certified, :description]
      config.create.columns << :upload_logo
      config.create.columns << :upload_store_image
      config.create.columns << :upload_license
      
      config.update.multipart  = true
      config.update.link.inline = false
      
      config.list.columns.exclude :address
      config.list.columns.exclude :province
      config.list.columns.exclude :city
      config.list.columns.exclude :map
      config.list.columns.exclude :description
      config.list.columns.exclude :upload_logo
      config.list.columns.exclude :upload_store_image
      config.list.columns.exclude :upload_license
      config.list.columns.exclude :props
      
      columns[:merchant].label = "商家"
      columns[:name].label = "店名"
      columns[:area].label = "区域"
      columns[:address].label = "地址"
      columns[:area].label = "区域"
      columns[:email].label = "电子邮件"
      columns[:province].label = "省"
      columns[:city].label = "城市"
      columns[:map].label = "地图"
      columns[:description].label = "描述"
      columns[:phone].label = "电话"
      columns[:mobile_phone].label = "手机"
      columns[:work_time].label = "营业时间"
	  columns[:disabled].label = "关闭"
      columns[:passed].label = "通过"
      columns[:certified].label = "审核"
      columns[:upload_logo].label = "Logo"
      columns[:upload_store_image].label = "店内照片"
      columns[:upload_license].label = "许可证"
      columns[:props].label = "属性"  
  end
  
  auto_complete_for :merchant, :username, :limit =>20, :order => "username ASC"
  
  protected
  def before_create_save(record)
    set_merchant(record)
  end
  
  def before_update_save(record)
    set_merchant(record)
  end
  
  private
  def set_merchant(record)
    merchant_username = params[:merchant][:username]
    merchant = Merchant.find_by_username(merchant_username)
    record.merchant_id = merchant.id
  end
end
